#include "mongoc/mongoc.h"
#include <iostream>
#include <string>
#include <mutex>

class MyMongoC
{
public:
    MyMongoC();
    ~MyMongoC();
    //连接
    bool Connect(const char* ip = "127.0.0.1", int port = 27017, const char* db = NULL, const char* user = NULL, const char* pwd = NULL);
    //插入
    bool Insert(const char* collection, bson_t* command);
    //查询
    mongoc_cursor_t* Query(const char* collection, bson_t* conditions, bson_t* query = NULL, int skip = 0, int limit = 0);
    //更新
    bool Update(const char* collection, bson_t* conditions, bson_t* update);
    //删除
    bool Delete(const char* collection, bson_t* conditions);
    //统计
    int64_t Count(const char* collection, bson_t* conditions, int skip = 0, int limit = 0);

private:
    //销毁成员变量
    void Destroy();

private:

    bson_error_t m_error;

    //客户端
    mongoc_client_t* m_client;

    //数据库对象
    mongoc_database_t* m_db;

    //数据库名
    std::string m_strDB;

    //互斥锁
    std::mutex m_mutex;
};